/*    */ package com.newcrm.manager;
/*    */ 
/*    */ import com.newcrm.db.CompanyExtManager;
/*    */ import com.newcrm.exception.ActiveCodeCheckException;
/*    */ import com.newcrm.util.Util;
/*    */ import java.net.URLEncoder;
/*    */ import java.util.Date;
/*    */ import net.sf.json.JSONObject;
/*    */ import org.apache.log4j.Logger;
/*    */ import org.jsoup.Connection;
/*    */ import org.jsoup.Jsoup;
/*    */ import org.jsoup.nodes.Document;
/*    */ 
/*    */ public class ActiveCodeCheckManager
/*    */ {
/* 25 */   private static Logger logger = Logger.getLogger(ExportManager.class
/* 26 */     .getName());
/*    */ 
/* 28 */   private static ActiveCodeCheckManager instance = null;
/*    */ 
/* 30 */   private Date checkPassDate = null;
/*    */ 
/*    */   public static ActiveCodeCheckManager getInstance() {
/* 33 */     if (instance == null) {
/* 34 */       instance = new ActiveCodeCheckManager();
/*    */     }
/* 36 */     return instance;
/*    */   }
/*    */ 
/*    */   public boolean checkActiveCode(int companyId)
/*    */     throws ActiveCodeCheckException
/*    */   {
/* 48 */     if ((this.checkPassDate != null) && (Util.isToday(this.checkPassDate))) {
/* 49 */       return true;
/*    */     }
/*    */ 
/* 53 */     CompanyExtManager companyExtManager = new CompanyExtManager();
/* 54 */     String activeCode = companyExtManager.getFieldValue(companyId, 
/* 55 */       14);
/*    */ 
/* 58 */     String checkCode = companyExtManager.getFieldValue(companyId, 
/* 59 */       16);
/* 60 */     String companyId2 = companyExtManager.getFieldValue(companyId, 
/* 61 */       15);
/*    */     try
/*    */     {
/* 65 */       StringBuffer searchUrl = new StringBuffer();
/* 66 */       searchUrl.append("http://oem.qikebao.com/activeCode?activeCode=")
/* 67 */         .append(URLEncoder.encode(activeCode, "UTF-8"))
/* 68 */         .append("&companyId2=")
/* 69 */         .append(URLEncoder.encode(companyId2, "UTF-8"))
/* 70 */         .append("&checkCode=")
/* 71 */         .append(URLEncoder.encode(checkCode, "UTF-8"));
/*    */ 
/* 73 */       Document doc = null;
/*    */       try {
/* 75 */         doc = Jsoup.connect(searchUrl.toString()).timeout(30000).get();
/*    */       } catch (Exception e) {
/* 77 */         logger.warn("activie code check failed, url:" + searchUrl, e);
/* 78 */         throw new ActiveCodeCheckException("注册码验证超时，请稍后再试");
/*    */       }
/* 80 */       JSONObject json = null;
/*    */       try {
/* 82 */         json = JSONObject.fromObject(doc.text());
/*    */       } catch (Exception e) {
/* 84 */         logger.warn("activie code check failed, body: " + doc.text(), e);
/* 85 */         throw new ActiveCodeCheckException("注册码验证超时，请稍后再试");
/*    */       }
/*    */ 
/* 89 */       if ("1".equals(Util.getJSONStringValue(json, "success")))
/*    */       {
/* 91 */         this.checkPassDate = new Date();
/* 92 */         return true;
/*    */       }
/*    */ 
/* 95 */       throw new ActiveCodeCheckException(Util.getJSONStringValue(json, 
/* 96 */         "message"));
/*    */     } catch (Exception ex) {
/* 98 */       logger.warn("activie code check failed ", ex);
/* 99 */     }throw new ActiveCodeCheckException("注册码验证超时，请稍后再试");
/*    */   }
/*    */ }

/* Location:           C:\E\referenceProject\CRM参考\qikebao\WEB-INF\lib\qikebao.jar
 * Qualified Name:     com.newcrm.manager.ActiveCodeCheckManager
 * JD-Core Version:    0.6.1
 */